package org.example.jccluboss.config;

import org.example.jccluboss.adapter.AliStorageAdapter;
import org.example.jccluboss.adapter.MinioStorageAdapter;
import org.example.jccluboss.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 啊昌
 * @date 2025/4/17 23:49
 * StorageConfig 文件存储config
 */
@Configuration
@RefreshScope  //Spring Cloud 提供的一个重要注解，用于实现配置的动态刷新功能
public class StorageConfig {

	@Value("${storage.service.type}")
	private String storageType;


	@Bean
	@RefreshScope //Spring Cloud 提供的一个重要注解，用于实现配置的动态刷新功能
	public StorageAdapter storageService() {
		switch (storageType) {
			case "minio":
				return new MinioStorageAdapter();
			case "aliyun":
				return new AliStorageAdapter();
			default:
				throw new IllegalArgumentException("未找到对应的文件存储处理器");
		}
	}
}
